import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';

import { unheadVueComposablesImports } from '@unhead/vue';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [VantResolver()],
      imports: [
        unheadVueComposablesImports,
      ],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      '/proxy_douguo': {
        target: 'https://apis.netstart.cn/douguo',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/proxy_douguo/, '')
      },
      '/proxy_image': {
        target: 'https://cp1.douguo.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/proxy_image/, '')
      }
    }
  }
})
